package com.lx.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lx.bean.Admin;
import com.lx.bean.Brand;
import com.lx.mapper.BrandMapper;
import com.lx.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class BrandServiceImpl implements BrandService {
    @Autowired
    private BrandMapper brandMapper;

    @Override
    public int addBrand(Brand brand) {
        int insert = brandMapper.insert(brand);
        return insert;
    }

    @Override
    public int removeBrand(Integer id) {
        int i = brandMapper.deleteById(id);
        return i;
    }

    @Override
    public int modifyBrand(Brand brand) {
        int i = brandMapper.updateById(brand);
        return i;
    }

    @Override
    public long getCount(Integer page, Integer limit) {
        //创建分页对象 构造分页参数
        Page<Brand> pageObj = new Page<>(page,limit);
        //调用分页查询的方法 selectPage
        Page<Brand> brandPage = brandMapper.selectPage(pageObj, null);
        //获取数据总条数
        long total = brandPage.getTotal();
        return total;
    }

    @Override
    public List<Brand> showPageBrand(Integer page, Integer limit) {
        //创建分页对象 构造分页参数
        Page<Brand> pageObj = new Page<>(page,limit);
        //调用分页查询的方法 selectPage
        Page<Brand> brandPage = brandMapper.selectPage(pageObj, null);
        List<Brand> brands = brandPage.getRecords();
        return brands;
    }
}
